<?php
class stats extends command {

	public function __construct(){
		$this->name = 'stats';		
		$this->public = false;
		$this->channels = array("#juchipila");
		$this->server = 'irc.juchipila.com';
	}

	public function help(){
		return "Uso: !stats. Mostrar información estadistica del chat.";
	}	
	
	public function process($args){
		if ( ! $this->issuedbyadmin){
			return 0;
		}
		$this->output = "";
		global $db;
		
		$this->output .= "----------- STATS ------------\n";
		
		$sql = "select count(1) as count from chatlogins";
		$r = $db->Parse($sql);
		$r->Execute();
		$row = $r->GetRow();
		$this->output .= "Número de logins: {$row->count}\n";

		$sql = "select count( distinct ip) as count from chatlogins";
		$r = $db->Parse($sql);
		$r->Execute();
		$row = $r->GetRow();
		$this->output .= "Número de ips únicas: {$row->count}\n";
		

		$sql = "select count( distinct nick) as count from chatlogins";
		$r = $db->Parse($sql);
		$r->Execute();
		$row = $r->GetRow();
		$this->output .= "Número de nicks únicos: {$row->count}\n";
				
		
		
		$sql = "select count(1) as count from chatkicks\n";
		$r = $db->Parse($sql);
		$r->Execute();
		$row = $r->GetRow();
		$this->output .= "Número de kicks: {$row->count}\n";
		
		$sql = "select count(1) as count from chatbans";
		$r = $db->Parse($sql);
		$r->Execute();
		$row = $r->GetRow();
		$this->output .= "Número de bans: {$row->count}\n";		
			
	}

	public function write(){
		$temp = preg_split("/\n/", $this->output, null, PREG_SPLIT_NO_EMPTY);
		foreach ( $temp as $line){
			fwrite($this->socket, "PRIVMSG " . $this->nick . " :" . $line . "\n");
			print "PRIVMSG " . $this->nick . " :" . $line . "\n";
		}
	}
}
?>